package com.yiqi.zhiyuan.feature.home.model;

import com.suozhang.framework.component.http.RxDataProcessFactory;
import com.yiqi.zhiyuan.entity.dto.LocationDTO;
import com.yiqi.zhiyuan.entity.dto.TaskDTO;
import com.yiqi.zhiyuan.entity.vo.CarVO;
import com.yiqi.zhiyuan.entity.vo.HomeVO;
import com.yiqi.zhiyuan.entity.vo.OrderVO;
import com.yiqi.zhiyuan.feature.home.contract.HomeContract;
import com.yiqi.zhiyuan.feature.home.dependencies.home.DaggerHomeModelComponent;
import com.yiqi.zhiyuan.framework.api.ApiLib;
import com.yiqi.zhiyuan.framework.api.HomeApi;

import java.util.List;

import javax.inject.Inject;

import io.reactivex.Observable;

/**
 * @ProjectName: ZhiYuan
 * @Description: 注册model
 * @Author: lijuwen
 * @CreateDate: 2019/3/13 13:07
 * @UpdateUser: 更新者
 * @UpdateDate: 2019/3/13 13:07
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
public class HomeModel implements HomeContract.Model {
    @Inject
    HomeApi api;

    public HomeModel() {
        DaggerHomeModelComponent.builder().apiComponent(ApiLib.apiComponent()).build().inject(this);
    }


    @Override
    public Observable<HomeVO> dosSelectDriverHomeInfo() {
        return api.selectDriverHomeInfo().compose(RxDataProcessFactory.<HomeVO>dataPrepAndIoToMainTransformer());
    }

    @Override
    public Observable<List<CarVO>> doSelectCarList() {
        return api.selectDriverCarList().compose(RxDataProcessFactory.<List<CarVO>>dataPrepAndIoToMainTransformer());
    }

    @Override
    public Observable<String> doOrderQuickSetup(Integer driverId, int type) {
        return api.orderQuickSetup(driverId,type).compose(RxDataProcessFactory.<String>dataPrepAndIoToMainTransformer());
    }

    @Override
    public Observable<OrderVO> doOrder(TaskDTO taskDTO) {
        return api.order(taskDTO).compose(RxDataProcessFactory.<OrderVO>dataPrepAndIoToMainTransformer());
    }

    @Override
    public Observable<OrderVO> doArriveAtLocation(TaskDTO taskDTO) {
        return api.arriveAtLocation(taskDTO).compose(RxDataProcessFactory.dataPrepAndIoToMainTransformer());
    }

    @Override
    public Observable<List<OrderVO>> doSelectMissedOrderList(LocationDTO locationDTO) {
        return api.selectMissedOrderList(locationDTO).compose(RxDataProcessFactory.dataPrepAndIoToMainTransformer());
    }
}

